$(function () {

//获取验证码

// /user/vCode


$('#getCode').on('tap',function(){
    $.ajax({
        url:"/user/vCode",
        type:'get',
        success:function(res) {
            console.log(res)
            $("#v_code").val(res.vCode)
          
        }
    })
})




  $("#reg").on("tap", function () {
    var account = $("#account").val().trim();
    var phone = $("#phone").val().trim();
    var password = $("#password").val().trim();
    var password_confirm = $("#password_confirm").val().trim();
    var v_code = $("#v_code").val().trim();

    if (account.length < 5) return alert("用户名最短为 5 个字符");

 
    var  reg= /^1[3-9]\d{9}$/


    if (!reg.test(phone)) return alert("手机号码不符合规则");

    if (password.length < 5) return alert("密码最短为 5 个字符");

    if (password !== password_confirm)
      return alert("两次输入密码不一致 重新输入密码");

    if (!v_code) return alert("验证码不能为空");

    // {"username":"zhoushugang","password":"123456","mobile":"15111111111","vCode":"DS7F"}

    var params = {
      username: account,
      password: password,
      mobile: phone,
      vCode: v_code,
    };

    $.ajax({
      url: "/user/register",
      type: "post",
      data: params,
      success: function (res) {
        console.log(res);
        if (res.success) {
          setTimeout(function () {
            window.location.href = "login.html";
          }, 1000);
        }
      },
    });
  });
});
